﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace LevelEditor
{
    public class ImageManager
    {
        #region Fields

        static ImageManager instance = new ImageManager();

        SortedList<string, Image> images;

        #endregion

        #region Constructors

        ImageManager()
        {
            images = new SortedList<string, Image>();
            images.Add("cliffveg.png", Properties.Resources.CLIFFVEG);
        }

        #endregion

        #region Destructors

        ~ImageManager()
        {
            foreach (KeyValuePair<string, Image> item in images)
                item.Value.Dispose();
        }

        #endregion

        #region Methods

        public static ImageManager GetInstance()
        {
            return instance;
        }

        public Image GetImageByName(string name)
        {
            name = name.ToLower();
            if (!images.ContainsKey(name))
            {
                try
                {
                    images.Add(name, Image.FromFile(name));
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error Loading File!");
                }
            }
            return images[name];
        }

        #endregion
    }
}
